package com.learn.hibernatevalidator.chapter12.constraintapi;

import jakarta.validation.*;
import jakarta.validation.constraintvalidation.SupportedValidationTarget;
import jakarta.validation.constraintvalidation.ValidationTarget;

import java.lang.annotation.*;

/**
 * @author: liyf
 * @create: 2025-01-24 22:29
 **/

@Documented
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = LuggageCountMatchesPassengerCount.Validator.class)
public @interface LuggageCountMatchesPassengerCount {

    String message() default "{com.learn.hibernatevalidator.chapter11.constraintapi.LuggageCountMatchesPassengerCount.message}";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * 跨参数验证必须定义一个成员 validationAppliesTo
     *
     * @return
     */
    ConstraintTarget validationAppliesTo() default ConstraintTarget.IMPLICIT;

    int piecesOfLuggagePerPassenger() default 1;

    @SupportedValidationTarget({
            ValidationTarget.ANNOTATED_ELEMENT,
            ValidationTarget.PARAMETERS
    })
    class Validator implements ConstraintValidator<com.learn.hibernatevalidator.chapter03.crossparameter.LuggageCountMatchesPassengerCount, Object[]> {

        @Override
        public boolean isValid(Object[] value, ConstraintValidatorContext context) {
            return false;
        }

        @Override
        public void initialize(com.learn.hibernatevalidator.chapter03.crossparameter.LuggageCountMatchesPassengerCount constraintAnnotation) {
            int value = constraintAnnotation.piecesOfLuggagePerPassenger();

        }
    }
}